package cn.cs.service.impl;

import cn.cs.client.RestClientBigUserClient;
import cn.cs.common.Constants;
import cn.cs.common.DateUtil;
import cn.cs.common.EmptyUtils;
import cn.cs.common.Page;
import cn.cs.pojo.ClientBigUser;
import cn.cs.pojo.ClientUser;
import cn.cs.service.ClientBigUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class ClientBigUserServiceImpl implements ClientBigUserService {

    @Resource
    private RestClientBigUserClient clientBigUserClient;


    public Integer addClientBigUser(ClientUser clientUser) throws Exception {
        clientUser.setCreateTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
        return clientBigUserClient.addClientBigUser(clientUser);
    }

    public Integer modifyClientBigUser(ClientUser clientUser) throws Exception {
        clientUser.setUpdateTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
        return clientBigUserClient.modifyClientBigUser(clientUser);
    }

    public Integer deleteClientBigUserById(Long id) throws Exception {
        return clientBigUserClient.deleteClientBigUserById(id);
    }

    public Page<ClientBigUser> queryClientBigUserPageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) throws Exception {
        Integer total = clientBigUserClient.getClientBigUserCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<ClientUser> clientBigUserList = clientBigUserClient.getClientBigUserListByMap(param);
        page.setRows(clientBigUserList);
        return page;
    }

    public Integer getMaxCode(String param) throws Exception{
        return clientBigUserClient.getMaxCode(param);
    }

}
